﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(ISaleItem))]
    partial class SaleItem:Entity,ISaleItem
    {


        IProduct _Product2;
        IProduct ISaleItem.Product
        {
            get
            {
                if (this._Product2 == null)
                {
                    this._Product2 = this.DataContext.Products
                        .Where(i => i.Id == this.ProductId)
                        .FirstOrDefault();
                }

                return this._Product2;
            }
            set
            {
                this._Product2 = value;
                this.ProductId = value.Id;
            }
        }

        List<IProductVariation> _ProductVariations2;
        List<IProductVariation> ISaleItem.ProductVariations
        {
            get
            {
                if (this._ProductVariations2 == null)
                {
                    this._ProductVariations2 = this.DataContext.ProductVariations
                        .Where(i => i.SaleItemId == this.Id)
                        .Select(i=>i as IProductVariation)
                        .ToList();
                }

                return this._ProductVariations2;
            }
            set
            {
                this._ProductVariations2 = value;
            }
        }
    }
}
